import time
from selenium.webdriver.common.by import By
from base.base_action import BaseAction


# 资源分类页
class ResourcesSortPage(BaseAction):

    # 资源管理按钮
    resources_btn = By.XPATH, "//span[text()='资源管理']"

    # 新建分类
    add_btn = By.XPATH, "//button/span[text()='新建分类']"

    # 分类名称
    sort_name = By.XPATH, "//textarea"

    # 确定按钮
    determine_btn = By.XPATH, "//span[text()='确 定']"

    # 分类名称搜索框
    sort_name_search = By.XPATH, "//input[@placeholder='搜索名称']"

    # 上移按钮
    move_up_btn = "document.getElementsByClassName('operate-style')[4].click();"

    # 下移按钮
    move_down_btn = "document.getElementsByClassName('operate-style')[4].click();"

    # 编辑按钮
    edit_btn = "document.getElementsByClassName('operate-style')[0].click();"

    # 删除按钮
    remove_btn = "document.getElementsByClassName('operate-style')[1].click();"

    # 删除弹出的"确定"按钮
    remove_determine_btn = By.XPATH, "/html/body/div[2]/div/div[3]/button[2]/span"

    #  点击资源管理
    def click_resources_manage(self):
        return self.click(self.resources_btn)

    # 点击新增按钮
    def click_add_btn(self):
        return self.click(self.add_btn)

    # 输入分类名称
    def input_sort_name(self, content):
        return self.input(self.sort_name, content)

    # 点击"确定"按钮
    def click_determine_btn(self):
        return self.click(self.determine_btn)

    # 清空资源名称输入框
    def clear_resources_name_input(self):
        return self.clear(self.sort_name)

    # 点击上移按钮
    def click_move_up_btn(self):
        return self.execute_js(self.move_up_btn)

    # 点击下移按钮
    def click_move_down_btn(self):
        return self.execute_js(self.move_down_btn)

    # 点击删除按钮
    def click_remove_btn(self):
        return self.click(self.remove_btn)

    # 删除的弹窗的"确定"按钮
    def click_remove_determine_btn(self):
        return self.click(self.remove_determine_btn)

    # 通过分类名称搜索分类
    def input_sort_name_search(self, content):
        return self.input(self.sort_name_search, content)



